﻿// ===============================================================================
// XCI.NET 西安交通信息WinForm开发框架 2018 版权所有
// ===============================================================================
using System;

namespace XCI.Windows
{
    /// <summary>
    /// 自定义属性描述
    /// </summary>
    public class PropertyDescriptorx : System.ComponentModel.PropertyDescriptor
    {
        #region 字段

        private readonly System.ComponentModel.PropertyDescriptor _proDescriptor;
        private string mCategory;
        private string mDisplayName;
        private string mDescription;

        #endregion

        #region 构造

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="proDescriptor">属性描述对象</param>
        public PropertyDescriptorx(System.ComponentModel.PropertyDescriptor proDescriptor)
            : base(proDescriptor)
        {
            this.mCategory = proDescriptor.Category;
            this.mDisplayName = proDescriptor.DisplayName;
            this.mDescription = proDescriptor.Description;
            this._proDescriptor = proDescriptor;
        }

        #endregion

        #region 属性

        /// <summary>
        /// 分类
        /// </summary>
        public override string Category
        {
            get { return mCategory; }
        }

        /// <summary>
        /// 显示名称
        /// </summary>
        public override string DisplayName
        {
            get { return mDisplayName; }
        }

        /// <summary>
        /// 描述
        /// </summary>
        public override string Description
        {
            get { return mDescription; }
        }

        /// <summary>
        /// 是否可重置值
        /// </summary>
        /// <param name="component">组件对象</param>
        /// <returns>可重置返回true</returns>
        public override bool CanResetValue(object component)
        {
            return _proDescriptor.CanResetValue(component);
        }

        /// <summary>
        /// 组件类型
        /// </summary>
        public override Type ComponentType
        {
            get { return _proDescriptor.ComponentType; }
        }

        /// <summary>
        /// 获取属性值
        /// </summary>
        /// <param name="component">组件对象</param>
        /// <returns>返回属性值</returns>
        public override object GetValue(object component)
        {
            return _proDescriptor.GetValue(component);
        }

        /// <summary>
        /// 设置属性值
        /// </summary>
        /// <param name="component">组件对象</param>
        /// <param name="value">属性值</param>
        public override void SetValue(object component, object value) { _proDescriptor.SetValue(component, value); }

        /// <summary>
        /// 是否只读
        /// </summary>
        public override bool IsReadOnly
        {
            get { return _proDescriptor.IsReadOnly; }
        }

        /// <summary>
        /// 属性类型
        /// </summary>
        public override Type PropertyType
        {
            get { return _proDescriptor.PropertyType; }
        }

        /// <summary>
        /// 重置值
        /// </summary>
        /// <param name="component">组件对象</param>
        public override void ResetValue(object component) { _proDescriptor.ResetValue(component); }

        #endregion

        #region 方法

        /// <summary>
        /// 
        /// </summary>
        /// <param name="component"></param>
        /// <returns></returns>
        public override bool ShouldSerializeValue(object component)
        {
            return _proDescriptor.ShouldSerializeValue(component);
        }

        /// <summary>
        /// 设置属性显示名称
        /// </summary>
        /// <param name="pDispalyName"></param>
        public void SetDisplayName(string pDispalyName)
        {
            mDisplayName = pDispalyName;
        }

        /// <summary>
        /// 设置属性分组
        /// </summary>
        /// <param name="pCategory"></param>
        public void SetCategory(string pCategory)
        {
            mCategory = pCategory;
        }

        /// <summary>
        /// 设置属性描述
        /// </summary>
        /// <param name="pDescription"></param>
        public void SetDescription(string pDescription)
        {
            mDescription = pDescription;
        }

        #endregion
    }
}